package com.yueya.api.employee;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.yueya.common.constant.CodeConst;
import com.yueya.common.service.BaseService;

import net.sf.json.JSONObject;

public class IEmployeeService extends BaseService {

	
	public Map<String, Object> getPageList(JSONObject jo) {
		Map<String, Object> map = new HashMap<String, Object>();

		if (containsKey(jo, "pgn", "pgs")) {
			pageNumber = jo.getInt("pgn");
			pageSize = jo.getInt("pgs");
			
			String select = "select esr.sign_record_id,esr.user_emp_id,esr.sign_time signtime,esr.device_name devicename,esr.remark,u.user_name empname ";
			StringBuffer sql = new StringBuffer(" from jg_emp_sign_record esr  ");
			sql.append(" left join t_user u on u.user_id = esr.user_emp_id where 1=1 ");
			
			// 护工姓名
			if (jo.containsKey("empname")) {
				String empName = jo.getString("empname");
				sql.append(" esr.user_name like '%"+empName+"%'");
			}

			// 老人姓名
			if (jo.containsKey("devicename")) {
				String deviceName = jo.getString("devicename");
				sql.append(" esr.device_name like '%"+deviceName+"%'");
			}

			// 日期
			if (jo.containsKey("startdate")) {
				String date = jo.getString("date");
				
			}
			
			
			Page<Record> page = Db.paginate(pageNumber, pageSize, select, sql.toString());
			map.put("code", CodeConst.SUCCESS);
			map.put("data", page);
		} else {
			map.put("code", CodeConst.JSONFORMAT_WRONG);
			map.put("msg", "JSON参数不合法");
		}
		// TODO Auto-generated method stub
		return map;
	}

}
